const {
    resolve
} = require('path');
var HtmlWebpackPlugin = require('html-webpack-plugin')
module.exports = {
    entry: './src/js/index.js',
    output: {
        filename: 'js/built.js',
        path: resolve(__dirname, 'build')
    },
    module: {
        rules: [

            {
                //处理css资源
                test: /\.css$/,
                use: ['style-loader', 'css-loader']
            },
            {
                //处理less资源
                test: /\.less$/,
                use: ['style-loader', 'css-loader', 'less-loader']
            },
            {
                //处理图片资源
                test: /\.(jpg|png|gif)$/,
                loader: 'url-loader',
                options: {
                    limit: 8 * 1024,
                    name: '[hash:8].[ext]',
                    // 关闭es6模块
                    esModule: false,
                    outputPath: 'imgs'
                }
            },
            {
                //处理html中图片
                test: /\.html$/,
                loader: 'html-loader'
            },
            {
                //打包其他资源（除了html/js/css资源）
                //exclude排除意思
                exclude: /\.(css|js|html|less|sass|jpg|png|gif)$/,
                loader: 'file-loader',
                options: {
                    name: '[hash:8].[ext]'
                }
            }

        ]
    },
    
    mode: 'development',
    devServer: {
        contentBase: resolve(__dirname, 'build'),
        compress: true,
        port: 3000,
        open: true
    }
};